home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Monitored data handler *)
- (* *)
- (* Copyright 1988, 1989, 1990 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- UNIT BBMON;
-
- INTERFACE
-
- PROCEDURE monitor_init;
- PROCEDURE monitor_up;
-
- IMPLEMENTATION
-
- USES
- DOS,
- bbaux,
- bbdummy,
- bbmisc,
- bbsema2,
- bbtime;
-
- PROCEDURE write_port_mon(p : port_block_ptr); FORWARD;
-
- VAR
- m_file : FILE OF port_call_item;
-
- (*===========================================================================*)
- (* Initialize monitor *)
- (*===========================================================================*)
-
- PROCEDURE monitor_init;
-
- VAR
- b : BOOLEAN;
- i : INTEGER;
- m_buffer : port_call_item;
- save_p : port_block_ptr;
-
- BEGIN;
-
- ASSIGN(m_file, opt_block.mon_fn);
-
- {$I-}
- RESET(m_file);
- i := IORESULT;
- {$I+}
-
- save_p := active_port;
-
- IF i = 0 THEN
- BEGIN;
-
- WHILE NOT EOF(m_file) DO
- BEGIN;
- READ(m_file, m_buffer);
- WITH m_buffer DO
- BEGIN;
-
- IF port_call_port < 'A' THEN
- BEGIN;
- b := TRUE;
- active_port := @dummy_port;
- END
- ELSE
- b := find_port(port_call_port);
-
- IF b THEN
- WITH active_port^ DO
- BEGIN;
- i := 1;
- WHILE (i <= opt_block.n_mon) AND
- (call_list^[i].port_call_date <> '') DO
- INC(i);
- IF i <= opt_block.n_mon THEN
- call_list^[i] := m_buffer;
- END;
- END;
- END;
-
- active_port := save_p;
- active_tcb^.tcb_port := save_p;
-
- CLOSE(m_file);
-
- END;
- END;
-
- (*===========================================================================*)
- (* Update monitor file *)
- (*===========================================================================*)
-
- PROCEDURE monitor_up;
-
- VAR
- i : BYTE;
- p : port_block_ptr;
-
- BEGIN;
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- REWRITE(m_file);
-
- write_port_mon(@dummy_port);
-
- p := ring_port;
- REPEAT
- write_port_mon(p);
- p := p^.next_port;
- UNTIL p = ring_port;
-
- CLOSE(m_file);
-
- free_semaphore(semaphore_interrupts);
-
- time_mon := up_time_from_now(10*60);
-
- END;
-
- (*===========================================================================*)
- (* Write a port to monitor file *)
- (*===========================================================================*)
-
- PROCEDURE write_port_mon(p : port_block_ptr);
-
- VAR
- i : BYTE;
-
- BEGIN;
- WITH p^ DO
- FOR i := 1 TO opt_block.n_mon DO
- BEGIN;
- IF call_list^[i].port_call_date = '' THEN
- EXIT;
- WRITE(m_file, call_list^[i]);
- END;
- END;
-
- END.